package com.register.dao;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class MemberCheck
 */
public class MemberCheck extends HttpServlet {
	private RegisterDAO registerDAO = null;

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);

	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userid = (String) request.getParameter("userid").trim();

		System.out.println("MemberCheck 호출");
		System.out.println("MemberCheck아이디는 " + userid);
		registerDAO = new RegisterDAO();
		boolean check = registerDAO.checkMember(userid);

		request.setAttribute("check", check);
		request.setAttribute("id", userid);

		System.out.println(check);
		String msg = null;
		String tf = null;
		if (!check) {

			msg = "ID가 있습니다.";
			tf = "red";

		} else {
			msg = "ID 사용이 가능합니다.";
			tf = "blue";
		}

		request.setAttribute("msg", msg);
		request.setAttribute("tf", tf);

		request.getRequestDispatcher("registerTest.forrest").forward(request, response);
	}

}
